package puzzle.common.point;

import tomoto.util.ArrayUtil;

public class PntHelper {
	public static Pnt[] getDirectNeighborPointsAround(int x, int y) {
		Pnt[] ps = new Pnt[4];
		ps[0] = new Pnt(x, y - 1);
		ps[1] = new Pnt(x + 1, y);
		ps[2] = new Pnt(x, y + 1);
		ps[3] = new Pnt(x - 1, y);
		return ps;
	}
	
	public static Pnt[] getDirectNeighborPointsAround(int x, int y, int xlimit, int ylimit) {
		Pnt[] ps = new Pnt[4];
		int i = 0;

		if (y >= 1) ps[i++] = new Pnt(x, y - 1);
		if (x < xlimit - 1) ps[i++] = new Pnt(x + 1, y);
		if (y < ylimit - 1) ps[i++] = new Pnt(x, y + 1);
		if (x >= 1) ps[i++] = new Pnt(x -1, y);

		return i == 4 ? ps : ArrayUtil.dup(ps, i);
	}
}
